package chapter06;

import java.util.concurrent.TimeUnit;

/**
 * @author chisheng
 * @since 2021-11-11
 */
public class ThreadGroupEnumerateThreads {

    public static void main(String[] args) throws InterruptedException {
        ThreadGroup customThreadGroup = new ThreadGroup("customThreadGroup");
        Thread customThread = new Thread(customThreadGroup, () -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "customThread");
        customThread.start();

        TimeUnit.MILLISECONDS.sleep(2);
        ThreadGroup currentThreadGroup = Thread.currentThread().getThreadGroup();

        Thread[] list = new Thread[currentThreadGroup.activeCount()];
        int recurseSize = currentThreadGroup.enumerate(list);
        System.out.println(recurseSize);

        recurseSize = currentThreadGroup.enumerate(list, false);
        System.out.println(recurseSize);
    }

}
